package asher.dotatbg.http.processor;

import java.io.IOException;
import java.net.Socket;
import java.util.Date;

import org.apache.log4j.Logger;

import asher.dotatbg.http.bean.HttpHeader;
import asher.dotatbg.http.responser.StaticRepository;
import asher.dotatbg.logfactory.LogFactory;

/**
 * 对于http请求的处理器
 * @author AsherYuan
 *
 */
public class HttpProcessor {
	
	private static Logger logger = LogFactory.getRootLogger();
	private HttpHeader header;
	private Socket socket;
	
	public HttpHeader getHeader() {
		return header;
	}
	public void setHeader(HttpHeader header) {
		this.header = header;
	}
	public Socket getSocket() {
		return socket;
	}
	public void setSocket(Socket socket) {
		this.socket = socket;
	}
	public HttpProcessor(HttpHeader header, Socket socket) {
		this.setHeader(header);
		this.setSocket(socket);
	}
	
	public void process() {
		String uri = header.getHttpRequestUri();
		if(uri.equals("/")) {
			uri = "index.html";
		} else if(uri.equals("/Game/")) {
			uri = "gameIndex.html";
		}
		
		try {
			StaticRepository sr = new StaticRepository(socket.getOutputStream());
			sr.sendStaticResource(uri);
		} catch (IOException e) {
			logger.info("静态资源库构造方法，获取socket的outputstream出错。" + "........." + new Date().toString());
		}
	}
}
